﻿using Gobang.Client.View.FrmPage;
using Gobang.ToolClass.Area;
using Gobang.ToolClass.Model;
using Sunny.UI;

namespace Gobang.Client.View.CustomControl
{
    public partial class ChessGameControl : UserControl
    {
        // 61447 人 361736 问号
        private string _gameName;
        public readonly CenterPage _centerPage;
        /// <summary>
        /// 是否为人机
        /// </summary>
        public bool IsManMachine { get; set; }
        public string DeskNum { get; set; }
        public ChessGameControl(string gameName, CenterPage centerPage)
        {
            InitializeComponent();
            _centerPage = centerPage;


            //uiSymbolButton1.Click += uiSymbolButton1_Click;
            //HideBtnJoin();
            //uiAvatar1.MouseMove += uiPanel4_MouseMove;
            //uiAvatar1.MouseLeave += uiPanel4_MouseLeave;
            //uiAvatar2.MouseMove += uiPanel4_MouseMove;
            //uiAvatar2.MouseLeave += uiPanel4_MouseLeave;
            //pictureBox1.MouseMove += uiPanel4_MouseMove;
            //pictureBox1.MouseLeave += uiPanel4_MouseLeave;
            //this.MouseMove += uiPanel4_MouseMove;
            //this.MouseLeave += uiPanel4_MouseLeave;
            //BindMouseMovAndLeave(this.Controls);

            SetGameName = gameName;
        }

        private void BindMouseMovAndLeave(ControlCollection controls)
        {
            foreach (Control ct in controls)
            {
                if (ct is UIPanel)
                {
                    var pn = ct as UIPanel;
                    pn.MouseMove += uiPanel4_MouseMove;
                    pn.MouseLeave += uiPanel4_MouseLeave;
                    BindMouseMovAndLeave(pn.Controls);
                }
            }
        }
        public string SetGameName
        {
            set
            {
                _gameName = value;
                this.uiPanel5.Text = _gameName;
            }
            get { return _gameName; }
        }
        public AreaNode Node { get; set; }
        public Room Room { get; set; }
        public void Join(ChessGame chessGame)
        {

        }

        private void uiPanel4_MouseMove(object sender, MouseEventArgs e)
        {
            ShowBtnJoin();
        }
        private void ShowBtnJoin()
        {
            //uiSymbolButton1.Show();
            //uiSymbolButton1.Cursor = Cursors.Hand;
            //uiSymbolButton1.Click -= uiSymbolButton1_Click;
            //uiSymbolButton1.Click += uiSymbolButton1_Click;

            //UISymbolButton _uISymbolButton;
            //_uISymbolButton = new UISymbolButton();
            //_uISymbolButton.Dock = DockStyle.Fill;
            //_uISymbolButton.Text = "加入";
            //_uISymbolButton.Symbol = 261694;
            //_uISymbolButton.StyleCustomMode = true;
            //uiSymbolButton1.Cursor = Cursors.Hand;
            //uiSymbolButton1.Click -= uiSymbolButton1_Click;
            //uiSymbolButton1.Click += uiSymbolButton1_Click;
            //uiPanel16.Controls.Add(_uISymbolButton);

        }
        private void HideBtnJoin()
        {
            //uiSymbolButton1.Hide();
            //uiPanel16.Controls.Clear();
        }
        private void uiPanel4_MouseLeave(object sender, EventArgs e)
        {
            HideBtnJoin();
        }
        /// <summary>
        /// 加入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uiSymbolButton1_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            uiContextMenuStrip1.Show(pictureBox1, (pictureBox1.Width - uiContextMenuStrip1.Width) >> 1, (pictureBox1.Height - uiContextMenuStrip1.Height) >> 1);
        }

        private void uiContextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            DeskNum = this.uiPanel5.Text;
            switch (e.ClickedItem.Name)
            {
                case "tsmiLook":// 加入观看
                    break;
                case "tsmiBattle":// 加入对决
                    _centerPage._mainPage._frmMain.Hide();
                    using (FrmGobangMain fgm = new FrmGobangMain(this))
                    {
                        fgm.ShowDialog();
                    }
                    _centerPage._mainPage._frmMain.Show();
                    break;
            }

        }
    }

    public class ChessGame : UserInfoModel
    {
        public bool IsChess { get; set; }
    }
}
